// pages/job/job.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title: '',
    reward: '',
    address: '',
    rdSession: '',
    telephone: '',
    workContent: '',
    requirements: '',
    workTime: '',
    boss:'',
    district: '校内',

    array: ['校内', '金平区', '龙湖区', '濠江区', '潮阳区', '潮南区', '澄海区'],
    objectArray: [
      {
        id: 0,
        name: '校内'
      },
      {
        id: 1,
        name: '金平区'
      },
      {
        id: 2,
        name: '龙湖区'
      },
      {
        id: 3,
        name: '濠江区'
      },
      {
        id: 4,
        name: '潮阳区'
      },
      {
        id: 5,
        name: '潮南区'
      }, {
        id: 6,
        name: '澄海区'
      }
    ],
    index: 0,
  },

  listenerTITLE: function (e) {
    this.data.title = e.detail.value;
  },

  listenerREWARD: function (e) {
    this.data.reward = e.detail.value;
  },

  listenerADDRESS: function (e) {
    this.data.address = e.detail.value;
  },

  listenerBOSS: function (e) {
    this.data.boss = e.detail.value;
  },

  listenerTELEPHONE: function (e) {
    this.data.telephone = e.detail.value;
  },

  listenerWORKCONTENT: function (e) {
    this.data.workContent = e.detail.value;
  },

  listenerREQUIREMENTS: function (e) {
    this.data.requirements = e.detail.value;
  },

  listenerWORKTIME: function (e) {
    this.data.workTime = e.detail.value;
  },

  listenerBUTTON: function (e) {

    if (this.data.title == '' || this.data.reward == '' || this.data.address == '' ||
      this.data.workTime == '' || this.data.boss == '' || this.data.telephone == '' ||
      this.data.workContent == '' || this.data.requirements == '' ) {
      wx.showToast({
        title: '有项目为空',
        icon: 'none',
      })
    }
    else {
      wx.request({
        url: app.globalData.urlPath +'postPartTime.action',
        header: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        method: "POST",
        data: {
          workContent: this.data.workContent,
          requirements: this.data.requirements,
          telephone: this.data.telephone,
          address: this.data.address,
          workTime: this.data.workTime,
          title: this.data.title,
          reward: this.data.reward,
          rdSession: app.globalData.rdSession,
          district: this.data.district,
          contact:this.data.boss
        },
        success: function (res) {
          console.log(res.data.status);
          if (res.data.status == '200') {
            wx.showToast({
              title: '发布成功',
              icon: 'success'
            })
          }
          if (res.data.status == '500') {
            wx.showToast({
              title: '发布失败',
              icon: 'none'
            })
          }
        }
      })
    }
  },

  bindPickerChange: function (e) {
    this.data.district = e.detail.value,
    this.setData({
      index: e.detail.value
    })
    this.data.district = this.data.objectArray[this.data.index].name
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})